package com.kfm.spring.util;

import org.apache.commons.codec.digest.Md5Crypt;

import java.nio.charset.StandardCharsets;

public class MD5Util {

    private static final String MD5_SALT = "kfmiao04";

    public static String encode(String str) {
        return encode(str, MD5_SALT);
    }


    public static String encode(String str, String salt) {
        return Md5Crypt.md5Crypt(str.getBytes(StandardCharsets.UTF_8), salt, "");
    }

    public static String encode(String str, int count) {
        String temp = str;
        for (int i = 0; i < count; i++) {
            temp = encode(temp);
        }
        return temp;
    }

    public static void main(String[] args) {
        System.out.println(encode("123456"));
    }

}